package dict.agency;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import utils.MailUtil;

public class DcpDict {
	
	public static Map<String, String> STATE = new HashMap<String, String>();
	public static Map<String, String> RISK = new HashMap<String, String>();
	public static Map<String, Long> ALERT = new HashMap<String, Long>();
	public static Map<String, Long> HIDE = new HashMap<String, Long>();
	
	
	static{
		
		STATE.put("0","Failed" );//成功
		STATE.put("1","Successed" );//成功
		STATE.put("0000","Congratulations ,transaction successful" );//成功
		STATE.put("205","Do Not Honor");
		STATE.put("551","Not Sufficient Funds");
		STATE.put("R0000","Hisk Risk");
		STATE.put("R0001","Hisk Risk");
		STATE.put("R0002","Hisk Risk");
		STATE.put("R0003","Hisk Risk");
		STATE.put("R0004","Hisk Risk");
		STATE.put("R0005","Hisk Risk");
		STATE.put("R0014","Hisk Risk");
		STATE.put("R0015","Hisk Risk");

		STATE.put("C0001","Configure Incorrect");
		STATE.put("C0002","Configure Incorrect");
		STATE.put("C0003","Configure Incorrect");
		STATE.put("C0004","Configure Incorrect");
		STATE.put("C0005","Configure Incorrect");
		STATE.put("C0006","Configure Incorrect");
		STATE.put("C0007","Configure Incorrect");
		STATE.put("C0008","Configure Incorrect");
		STATE.put("C0009","Configure Incorrect");
		STATE.put("C0010","Configure Incorrect");
		STATE.put("C0011","Configure Incorrect");
		STATE.put("C0012","Configure Incorrect");
		STATE.put("C0013","No Support Card Type");
		STATE.put("S0013","System Failure");
		STATE.put("S0014","System Failure");

		STATE.put("E0001","Operate Failure");
		STATE.put("E0002","Operate Failure");
		STATE.put("E0006","Operate Failure");
		STATE.put("E0007","Operate Failure");
		STATE.put("E0008","Operate Repeat");

		STATE.put("T0001","Test Succ");
		STATE.put("T0002","Test Waiting");
		STATE.put("T0003","Test Pay Succ");
		STATE.put("T0004","Payment Failure");
		STATE.put("T0005","Payment Pending");

		STATE.put("I0001","Invalid Parameters");
		STATE.put("I0001","Invalid Parameters");
		STATE.put("I0002","Invalid Parameters");
		STATE.put("I0003","Invalid Parameters");
		STATE.put("I0004","Invalid Parameters");
		STATE.put("I0005","Invalid Parameters");
		STATE.put("I0006","Invalid Parameters");
		STATE.put("I0007","Invalid Parameters");
		STATE.put("I0008","Invalid Parameters");
		STATE.put("I0009","Invalid Parameters");
		STATE.put("I0010","Invalid Parameters");
		STATE.put("I0011","Invalid Parameters");
		STATE.put("I0012","Invalid Parameters");
		STATE.put("I0013","Invalid Parameters");
		STATE.put("I0014","Invalid Parameters");
		STATE.put("I0015","Invalid Parameters");
		STATE.put("I0016","Invalid Parameters");
		STATE.put("I0017","Invalid Parameters");
		STATE.put("I0018","Invalid Parameters");
		STATE.put("I0019","Invalid Parameters");
		STATE.put("I0020","Invalid Parameters");
		STATE.put("I0021","Invalid Parameters");
		STATE.put("I0022","Invalid Parameters");
		STATE.put("I0023","Invalid Parameters");
		STATE.put("I0024","Invalid Parameters");
		STATE.put("I0025","Invalid Parameters");
		STATE.put("I0026","Invalid Parameters");
		STATE.put("I0027","Invalid Parameters");
		STATE.put("I0028","Invalid Parameters");
		STATE.put("I0029","Invalid Parameters");
		STATE.put("I0030","Invalid Parameters");
		STATE.put("I0031","Invalid Parameters");
		STATE.put("I0032","Invalid Parameters");
		STATE.put("I0033","Invalid Parameters");
		STATE.put("I0034","Invalid Parameters");
		STATE.put("I0035","Invalid Parameters");
		STATE.put("I0036","Invalid Parameters");
		STATE.put("I0037","Invalid Parameters");
		STATE.put("I0038","Invalid Parameters");
		STATE.put("I0039","Invalid Parameters");
		STATE.put("I0040","Invalid Parameters");
		STATE.put("I0041","Invalid Parameters");
		STATE.put("I0042","Invalid Parameters");
		STATE.put("I0043","Invalid Parameters");
		STATE.put("I0044","Invalid Parameters");
		STATE.put("I0045","Invalid Parameters");
		STATE.put("I0046","Invalid Parameters");
		STATE.put("I0047","Invalid Parameters");
		STATE.put("I0048","Invalid Parameters");
		STATE.put("I0049","Invalid Parameters");
		STATE.put("I0050","Invalid Parameters");
		STATE.put("I0051","Invalid Parameters");
		STATE.put("I0052","Invalid Parameters");
		STATE.put("I0053","Invalid Parameters");
		STATE.put("I0054","Invalid Parameters");
		STATE.put("I0055","Invalid Parameters");
		STATE.put("I0056","Invalid Parameters");
		STATE.put("I0057","Invalid Parameters");
		STATE.put("I0058","Invalid Parameters");
		STATE.put("I0059","Invalid Parameters");
		STATE.put("I0060","Invalid Parameters");
		STATE.put("I0061","Invalid Parameters");
		STATE.put("I0062","Invalid Parameters");
		STATE.put("I0063","Invalid Parameters");
		STATE.put("I0064","Invalid Parameters");
		STATE.put("I0065","Invalid Parameters");
		STATE.put("I0066","Invalid Parameters");
		STATE.put("I0067","Invalid Parameters");
		STATE.put("I0068","Invalid Parameters");
		STATE.put("I0069","Invalid Parameters");
		STATE.put("I0070","Invalid Parameters");
		STATE.put("I0071","Invalid Parameters");
		STATE.put("I0072","Invalid Parameters");
		STATE.put("I0073","Invalid Parameters");
		STATE.put("I0074","Invalid Parameters");
		STATE.put("I0075","Invalid Parameters");
		STATE.put("I0076","Invalid Parameters");
		STATE.put("I0077","Invalid Parameters");
		STATE.put("I0078","Invalid Parameters");
		STATE.put("I0079","Invalid Parameters");
		STATE.put("I0080","Invalid Parameters");
		STATE.put("I0081","Invalid Parameters");
		STATE.put("I0082","Invalid Parameters");
		STATE.put("I0083","Invalid Parameters");
		STATE.put("I0084","Invalid Parameters");
		STATE.put("I0085","Invalid Parameters");
		STATE.put("I0086","Invalid Parameters");
		STATE.put("I0087","Invalid Parameters");
		STATE.put("I0088","Invalid Parameters");
		STATE.put("I0089","Invalid Parameters");
		STATE.put("I0090","Invalid Parameters");
		STATE.put("I0091","Invalid Parameters");
		STATE.put("I0092","Invalid Parameters");
		STATE.put("I0093","Invalid Parameters");
		STATE.put("I0094","Invalid Parameters");
		STATE.put("I0095","Invalid Parameters");
		STATE.put("I0096","Invalid Parameters");
		STATE.put("I0097","Invalid Parameters");
		STATE.put("I0098","Invalid Parameters");
		STATE.put("I0099","Invalid Parameters");
		STATE.put("I0100","Invalid Parameters");
		STATE.put("I0101","Invalid Parameters");
		STATE.put("I0102","Invalid Parameters");
		STATE.put("I0103","Invalid Parameters");
		STATE.put("I0104","Invalid Parameters");
		STATE.put("I0105","Invalid Parameters");
		STATE.put("I0106","Invalid Parameters");
		STATE.put("I0107","Invalid Parameters");
		STATE.put("I0108","Invalid Parameters");
		STATE.put("I0109","Invalid Parameters");
		STATE.put("I0110","Invalid Parameters");
		STATE.put("I0111","Invalid Parameters");
		STATE.put("I0112","Invalid Parameters");
		STATE.put("I0113","Invalid Parameters");
		STATE.put("I0114","Invalid Parameters");
		STATE.put("I0115","Invalid Parameters");
		STATE.put("I0116","Invalid Parameters");
		
		RISK.put("R0000", "R0000");
		
		ALERT.put("555", 0L);
		
		//HIDE.put("9905", 0);
	}
	
	
	public static synchronized String message(String code){
		if(STATE.containsKey(code)){
			return STATE.get(code).toString();
		}
		return "unknown exception";
	}
	
	public static synchronized void warning(String code,int limit){
		String name="DCP";
		String time= new SimpleDateFormat("HH:mm:ss").format(new Date());
		if(ALERT.containsKey(code)){
			ALERT.put(code, ALERT.get(code)+1);
			if(new Integer(ALERT.get(code).toString())>limit){
				ALERT.put(code, 0L);
				MailUtil.sendEmail(MailUtil.tos, "警告", "[" + time+ "]"+name+"返回码["+code+"]超过["+limit+"]次");
			}
		}
	}
	
}
